﻿Public Class Menus
    Private mCategories As List(Of MenuCategory)
    Public ReadOnly Property CategoryList As List(Of MenuCategory)
        Get
            Return mCategories
        End Get
    End Property
    Sub New()
        CreateMainMenu()
    End Sub
    Sub CreateMainMenu()
        mCategories = New List(Of MenuCategory)
        Dim cat As ListViewGroup
        Dim itms As List(Of ListViewItem)

        'Navigation
        cat = New ListViewGroup With {.Header = "Navigation", .HeaderAlignment = HorizontalAlignment.Center}
        itms = New List(Of ListViewItem)
        itms.Add(New ListViewItem With {.ImageIndex = 0, .Text = "Home", .Tag = AppHome, .Group = cat})
        itms.Add(New ListViewItem With {.ImageIndex = 1, .Text = "Exit", .Tag = AppExit, .Group = cat})
        If gApp.UpdateAvailable = True Then itms.Add(New ListViewItem With {.ImageIndex = 10, .Text = "Update", .Tag = AppUpd, .Group = cat})
        mCategories.Add(New MenuCategory With {.Category = cat, .Items = itms})

        'Applications
        cat = New ListViewGroup With {.Header = "Applications", .HeaderAlignment = HorizontalAlignment.Center}
        itms = New List(Of ListViewItem)

        If gUDApp.SelectedAppID = 0 Then
            itms.Add(New ListViewItem With {.ImageIndex = MenuImage.AppAdd, .Text = "Add New", .Tag = AppNew, .Group = cat})
        Else
            itms.Add(New ListViewItem With {.ImageIndex = MenuImageIndex(), .Text = "Edit", .Tag = AppEdit, .Group = cat})
            itms.Add(New ListViewItem With {.ImageIndex = MenuImage.AppErase, .Text = "Delete", .Tag = AppDelete, .Group = cat})
        End If
        mCategories.Add(New MenuCategory With {.Category = cat, .Items = itms})

        If gUDApp.SelectedAppID <> 0 Then
            'Files
            cat = New ListViewGroup With {.Header = "Files", .HeaderAlignment = HorizontalAlignment.Center}
            itms = New List(Of ListViewItem)
            itms.Add(New ListViewItem With {.ImageIndex = MenuImage.Files, .Text = "Manage", .Tag = FilMan, .Group = cat})
            itms.Add(New ListViewItem With {.ImageIndex = MenuImage.ServerClean, .Text = "Clean Server", .Tag = FilCln, .Group = cat})
            mCategories.Add(New MenuCategory With {.Category = cat, .Items = itms})

            'Settings
            cat = New ListViewGroup With {.Header = "Settings", .HeaderAlignment = HorizontalAlignment.Center}
            itms = New List(Of ListViewItem)
            itms.Add(New ListViewItem With {.ImageIndex = MenuImage.Settings, .Text = "Manage", .Tag = SetMan, .Group = cat})
            mCategories.Add(New MenuCategory With {.Category = cat, .Items = itms})

            'Versions
            cat = New ListViewGroup With {.Header = "Versions", .HeaderAlignment = HorizontalAlignment.Center}
            itms = New List(Of ListViewItem)
            itms.Add(New ListViewItem With {.ImageIndex = MenuImage.Version, .Text = "Manage", .Tag = VerMan, .Group = cat})
            mCategories.Add(New MenuCategory With {.Category = cat, .Items = itms})
        End If

        'General
        cat = New ListViewGroup With {.Header = "Help", .HeaderAlignment = HorizontalAlignment.Center}
        itms.Add(New ListViewItem With {.ImageIndex = MenuImage.Help, .Text = "Help", .Tag = AppHelp, .Group = cat})
        itms.Add(New ListViewItem With {.ImageIndex = MenuImage.Info, .Text = "Info", .Tag = AppInfo, .Group = cat})
        itms.Add(New ListViewItem With {.ImageIndex = MenuImage.Library, .Text = "Libraries", .Tag = AppLib, .Group = cat})
        itms = New List(Of ListViewItem)

        mCategories.Add(New MenuCategory With {.Category = cat, .Items = itms})
    End Sub
    Public Class MenuCategory
        Public Property Category As ListViewGroup
        Public Property Items As List(Of ListViewItem)
    End Class
    Function MenuImageIndex() As Integer
        Select Case gUDApp.SelectedAppStatus
            Case Is = UpdateApp.AppStatus.NewApp
                Return MenuImage.NewApp
            Case Is = UpdateApp.AppStatus.DefinedApp
                Return MenuImage.DefinedApp
            Case Is = UpdateApp.AppStatus.PublishedApp
                Return MenuImage.PublishedApp
        End Select
        Return MenuImage.NewApp
    End Function
    Enum MenuImage
        Home = 0
        Close = 1
        Help = 2
        AppAdd = 3
        AppEdit = 4
        AppErase = 5
        Version = 6
        Files = 7
        Info = 8
        ServerClean = 9
        Update = 10
        Settings = 11
        NewApp = 12
        PublishedApp = 13
        DefinedApp = 14
        Pack = 15
        Sign = 16
        Library = 17
    End Enum
End Class
